home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCmark_roots.c < prev    next >
C/C++ Source or Header  |  1991-09-11  |  4KB  |  121 lines

  1.  
  2. /* begincopyright
  3.   Copyright (c) 1988,1990 Xerox Corporation. All rights reserved.
  4.   Use and copying of this software and preparation of derivative works based
  5.   upon this software are permitted. Any distribution of this software or
  6.   derivative works must comply with all applicable United States export
  7.   control laws. This software is made available AS IS, and Xerox Corporation
  8.   makes no warranty about the software, its performance or its conformity to
  9.   any specification. Any person obtaining a copy of this software is requested
  10.   to send their name and post office or electronic mail address to:
  11.     PCR Coordinator
  12.     Xerox PARC
  13.     3333 Coyote Hill Rd.
  14.     Palo Alto, CA 94304
  15.     
  16.   Parts of this software were derived from code bearing the copyright notice:
  17.   
  18.   Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  19.   This material may be freely distributed, provided this notice is retained.
  20.   This material is provided as is, with no warranty expressed or implied.
  21.   Use at your own risk.
  22.   
  23.   endcopyright */
  24.   
  25. # include "xr/GCPrivate.h"
  26.  
  27. /*
  28.  * Boehm, April 17, 1990 5:36:21 pm PDT
  29.  */
  30.  
  31. /* Call the mark routines (GC_tl_mark for a single pointer, GC_mark_all */
  32. /* on groups of pointers) on every top level accessible pointer.        */
  33. /* Caller will presumably call mark to mark everything reachable     */
  34. /* through them.                            */
  35. /* This is source language specific.  The following works for PCR.      */
  36. /* Mark_clean specifies whether roots on clean pages should be        */
  37. /* considered.                                */
  38.  
  39. void GC_mark_roots(mark_clean)
  40. bool mark_clean;
  41. {
  42.     int * dummy = 0;
  43.  
  44.     /* Make sure mark stack is empty */
  45.         if (GC_mark_stack_top != GC_mark_stack_bottom) {
  46.             GC_abort("GC_mark_roots 0");
  47.         }
  48.         
  49.     /*
  50.      * We don't need to mark from registers, since they are also
  51.      * in the thread structure or on the stack.
  52.      */
  53.  
  54.     /* mark from the static and bss areas of each module */
  55.     {
  56.         struct data_list *d, *XR_get_data_list();
  57.         int i;
  58.         for (i=0; d = XR_get_data_list(i); i++) {
  59.         GC_tl_mark_all_but_gc(d->start, d->end, mark_clean);
  60.         }
  61.     }
  62.  
  63.     /* mark from the various other stacks */
  64.     XR_ApplyToSysMem (GC_tl_mark_all_but_gc, mark_clean);
  65. }
  66.  
  67.  
  68. /* Top level mark routine. Mark from the object pointed to by p.       */
  69. /* This is defined here, since alignment is not an explicit parameter. */
  70. /* Thus the routine is language specific.                              */
  71. /* Tl_mark is normally called by mark_regs, and thus must be defined.  */
  72. void GC_tl_mark(p)
  73. word * p;
  74. {
  75.     word * q;
  76.  
  77.     q = p;
  78. #   ifdef INTERIOR_STACK_POINTERS
  79.         GC_mark_all(&q, (&q)+1, ALIGNMENT, ALL_POINTERS, TRUE);
  80. #   else
  81.         GC_mark_all(&q, (&q)+1, ALIGNMENT, ALL_POINTERS, FALSE);
  82. #   endif
  83. }
  84.  
  85. /* Interface to mark_all that does not require alignment parameter.  */
  86. /* Defined here to keep mach_dep.c programming language independent. */
  87. void GC_tl_mark_all(b,t)
  88. word *b, *t;
  89. {
  90.     bool coerce_pointers = FALSE;
  91.     
  92. #   ifdef INTERIOR_STACK_POINTERS
  93.       if (b >= (word *)GC_heaplim /* stack area */) {
  94.         coerce_pointers = TRUE;
  95.       }
  96. #   endif INTERIOR_STACK_POINTERS
  97.     GC_mark_all(b, t, ALIGNMENT, ALL_POINTERS, coerce_pointers);
  98. }
  99.  
  100. /* Similar to GC_tl_mark_all, except that gc data area is explicitly */
  101. /* skipped over if it is encountered.                     */
  102. /* Always returns TRUE, to keep XR_ApplyToSysMem happy.             */
  103. bool GC_tl_mark_all_but_gc(b,t,mark_clean)
  104. word *b, *t;
  105. {
  106.     bool coerce_pointers = FALSE;
  107.     
  108. #   ifdef INTERIOR_STACK_POINTERS
  109.       if (b >= (word *)GC_heaplim /* stack area */) {
  110.         coerce_pointers = TRUE;
  111.       }
  112. #   endif INTERIOR_STACK_POINTERS
  113.     if (b <= &GC_first_global && &GC_last_global <= t) {
  114.         GC_mark_all(b, &GC_first_global, ALIGNMENT, mark_clean, FALSE);
  115.         GC_mark_all(&GC_last_global, t, ALIGNMENT, mark_clean, FALSE);
  116.     } else {
  117.         GC_mark_all(b, t, ALIGNMENT, mark_clean, coerce_pointers);
  118.     }
  119.     return(TRUE);
  120. }
  121.